// miniprogram/pages/heros/heros.js
const {newList} = require('../../data/circleList')

const {getHeroOrderByType} = require("../../data/allHeros")
const {getNewsPost} = require("../../data/allHeros")
const {updataNewsPost} = require("../../data/allHeros")

const {newsHeros} = require("../../data/herosMap")
const {newsPorter} = require('../../data/circleList')
const type=["战士","法师","坦克","刺客","射手","辅助"]

Page({

  /**
   * 页面的初始数据
   */
  data: {
    zhanshi:[],
    fashi:[],
    tanke:[],
    cike:[],
    sheshou:[],
    fuzhu:[],
    activeBtn: 1,
    newList,
    newsPorter,
    newsHeros: [],
    upListTitle: "英雄上分排行榜",
    upListDesc: "12月 黄忠-最强MVP射手",
    upListHeros: ["https://game.gtimg.cn/images/yxzj/img201606/heroimg/110/110.jpg",
      "https://game.gtimg.cn/images/yxzj/img201606/heroimg/155/155.jpg",
      "https://game.gtimg.cn/images/yxzj/img201606/heroimg/177/177.jpg"
    ],
    inputShowed: false,
    inputVal: ""
},

showInput() {
    this.setData({
        inputShowed: true
    });
    wx.navigateTo({
        url: '../search/search',
      })
},
hideInput() {
    this.setData({
        inputVal: "",
        inputShowed: false
    });
},
clearInput(){
    this.setData({
        inputVal: ""
    });
},
inputTyping(e) {
    this.setData({
        inputVal: e.detail.value
    });
    // console.log(this.data.inputVal);
},
changePages(e){
    let {id} = e.currentTarget.dataset
    this.setData({
        activeBtn: id
    })
},

async getHeroType(){
    this.setData({
        zhanshi:await getHeroOrderByType(type[0]),
        fashi:await getHeroOrderByType(type[1]),
        tanke:await getHeroOrderByType(type[2]),
        cike:await getHeroOrderByType(type[3]),
        sheshou:await getHeroOrderByType(type[4]),
        fuzhu:await getHeroOrderByType(type[5]),
    })
},
async getnewsPost(){
    this.setData({
        newsPorter:await getNewsPost()
    })
},
getNewHeros(){
    this.setData({
       newsHeros:newsHeros
    }) 
},
// 修改点赞数
async onSupport(e){
    let {id,supported,support} = e.detail
    if(!supported){

        await updataNewsPost(id,support+1,supported)
    }else{

        await updataNewsPost(id,support-1,supported)
    }
    this.getnewsPost()
},
  /**
   * 生命周期函数--监听页面加载
   */
onLoad(options) {
    this.getNewHeros()
    this.getHeroType()
    this.getnewsPost()
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})